package com.tuanbiao.models.action;

import com.abiao.lib_utils.StringUtils;
import com.hzjq.data.hzjq.entity.CapRecordEntity;
import com.hzjq.lib.BlastKool;
import com.hzjq.lib.sort.Sort;
import com.tuanbiao.constants.Constants;
import com.tuanbiao.data.callback.OnBaseResultCallback;

import java.util.List;

/**
 * @author abiao
 * @since 2022/4/20 15:11
 */
public interface SortAction {
    default void sort(@Constants.DetonatorSortType String sortType, @Constants.DetonatorOrderType String orderType, List<CapRecordEntity> entities, OnBaseResultCallback<String> callback) {
        Sort sort;
        if (StringUtils.equals(orderType, Constants.DetonatorOrderTypes.DOWN)) {
            sort = Sort.DOWN;
        } else {
            sort = Sort.UP;
        }
        switch (sortType) {
            case Constants.DetonatorSortTypes.ROW:
                BlastKool.Companion.loader().sort().sortByHole(sort, entities, () -> callback.onSuccess(sortType));
                break;
            case Constants.DetonatorSortTypes.DELAY:
                BlastKool.Companion.loader().sort().sortByDelay(sort, entities, () -> callback.onSuccess(sortType));
                break;
            case Constants.DetonatorSortTypes.UID:
                BlastKool.Companion.loader().sort().sortByUid(sort, entities, () -> callback.onSuccess(sortType));
                break;
            default:
                break;
        }
        callback.onFinish();
    }
}
